
/*****************************************************************************\
 *                              topology
\*****************************************************************************/

/*! @file 
 *
 *  @brief
 *    Testprogram for class Topology.
 *
 *  @author Gabriel Zachmann
 *	- reimplemented by Weiyu Yi, wyi@tu-clausthal.de
 *  
 *  @todo
 *    topology.out neu erzeugen, wenn OSG's Kugel in Ordnung ist, d.h.,
 *    dass Punkte nicht mehrfach vorkommen.
 */


//---------------------------------------------------------------------------
//  Includes
//---------------------------------------------------------------------------


#include <stdlib.h>
#include <stdio.h>

#include <ColTopology.h>
#include <ColUtils.h>
#include <ColUtilsOpenGL.h>

using col::Point3;
using col::ColGeometry;

//**************************************************************************
// Utility functions
//**************************************************************************

void printPnt( const Point3 &pnt )
{
	fprintf( stdout, "% 8f % 8f % 8f\n",
			(double)pnt[0],
			(double)pnt[1],
			(double)pnt[2] );

}
void printPoints( col::ColGeometry * geo )
{
	for ( unsigned int i=0; i<geo->getPointsPtr()->size(); i++ )
	{
		printPnt( geo->getPointsPtr()->at(i) );
	}
}


//**************************************************************************
// main
//**************************************************************************

int main( void )
{
	Point3 pnt[8] = { Point3(-1,-1, 1),
		Point3( 1,-1, 1),
		Point3( 1, 1, 1),
		Point3(-1, 1, 1),
		Point3(-1,-1,-1),
		Point3( 1,-1,-1),
		Point3( 1, 1,-1),
		Point3(-1, 1,-1)
	};
    unsigned int face[6][col::Dop::NumOri] = { {0,1,2,3},
		{1,5,6,2},
		{2,6,7,3},
		{0,3,7,4},
		{0,4,5,1},
		{4,7,6,5}
										};
    unsigned int face_nv[6] = { 4, 4, 4, 4, 4, 4 };

	col::Topology topo1( face, 6, face_nv );

	puts("\nCube from array:\n");
	puts("points:");
	for ( int i = 0; i < 8; i ++ )
		printPnt( pnt[i] );
	puts("topology:");
	topo1.print();

	ColGeometry * geom = new ColGeometry();
    std::string filepath( FILE_LOAD_PATH );
    std::string filename( "topology/topology_plane_case_1.obj" );
    col::loadGeometryFromFile( geom, ( filepath+filename ).c_str() );
	//col::loadGeometryFromFile( geom, "../../../coll/wrapper/wrapper_opengl/test/Data/topology/topology_plane_case_1.obj" );
	col::Topology topo2( geom );

	puts("\nPlane:\n");
	puts("points:");
	printPoints( geom );
	puts("topology:");
	topo2.print();

	delete geom;
	geom = new ColGeometry();
    std::string filepath2( FILE_LOAD_PATH );
    std::string filename2( "topology/topology_sphere_case_2.obj" );
    col::loadGeometryFromFile( geom, ( filepath2 + filename2 ).c_str() );
	//col::loadGeometryFromFile( geom, "../../../coll/wrapper/wrapper_opengl/test/Data/topology/topology_sphere_case_2.obj" );
	col::Topology topo3( geom );

	puts("\nSphere:\n");
	puts("points:");
	printPoints( geom );
	puts("topology:");
	topo3.print();

	delete geom;
	geom = new ColGeometry();
    std::string filepath3( FILE_LOAD_PATH );
    std::string filename3( "topology/topology_torus_case_3.obj" );
    col::loadGeometryFromFile( geom, ( filepath3 + filename3 ).c_str() );
	//col::loadGeometryFromFile( geom, "../../../coll/wrapper/wrapper_opengl/test/Data/topology/topology_torus_case_3.obj" );
	col::Topology topo4( geom, true, 1E-4 );

	puts("\nTorus with vertex unification:\n");
	puts("points:");
	printPoints( geom );
	puts("topology:");
	topo4.print();

	delete geom;
	geom = new ColGeometry();
    std::string filepath4( FILE_LOAD_PATH );
    std::string filename4( "topology/topology_torus_case_4.obj" );
    col::loadGeometryFromFile( geom, ( filepath4 + filename4 ).c_str() );
	//col::loadGeometryFromFile( geom, "../../../coll/wrapper/wrapper_opengl/test/Data/topology/topology_torus_case_4.obj" );
	topo4.createFromGeom( geom, false, 0 );

	puts("\nTorus without vertex unification:\n");
	puts("points:");
	printPoints( geom );
	puts("topology:");
	topo4.print();

	delete geom;
	geom = new ColGeometry();
    std::string filepath5( FILE_LOAD_PATH );
    std::string filename5( "topology/topology_box_case_5.obj" );
    col::loadGeometryFromFile( geom, ( filepath5 + filename5 ).c_str() );
	//col::loadGeometryFromFile( geom, "../../../coll/wrapper/wrapper_opengl/test/Data/topology/topology_box_case_5.obj" );
	col::Topology topo5( geom );		// does not do unification by default
	puts("\nBox:\n");
	puts("points:");
	printPoints( geom );
	puts("topology:");
	topo5.print();

	return 0;
}


char cvsid[] =
"@(#)$Id: topology.cpp,v 1.6 2004/03/09 13:41:36 ehlgen Exp $";



/**  Zum Abpasten fuer eine Funktion, Methode, oder Makro-"Funktion".
 *
 * @param param1	Comment for param1
 *
 * @return
 *   Text for return value.
 *
 * Detaillierte Beschreibung ...
 *
 * @throw Exception
 *   Beschreibung ..
 *
 * @warning
 *   Dinge, die der Aufrufer unbedingt beachten muss...
 *
 * @pre
 *   Annahmnen, die die Funktion macht...
 *
 * @sideeffects
 *   Nebenwirkungen, globale Variablen, die veraendert werden, ..
 *
 * @todo
 *   Was noch getan werden muss
 *
 * @bug
 *   Bekannte Bugs dieser Funktion
 *
 * @see
 *   ...
 *
 * @implementation
 *   Implementierungsdetails, TODOs, ...
 *
 **/

